#include "SimulatorGui.h"

using namespace OgreBites;

SimulatorGui::SimulatorGui(SdkCameraMan *mCameraMan, SdkTrayManager *mTrayMgr)
{
	std::cout << "\n Initializing SimulatorGui";
	this->mCameraMan = mCameraMan;
	this->mTrayMgr = mTrayMgr;

	mLoadingLabel = mTrayMgr->createLabel(OgreBites::TL_CENTER, "TLoading", "", 400);
	mTrayMgr->removeWidgetFromTray(mLoadingLabel);
	mLoadingLabel->hide();

	mMainMenu = new SimulatorMainMenu(mTrayMgr);
	mMainMenu->hide();


	mCameraMenu = mTrayMgr->createLongSelectMenu(OgreBites::TL_TOPLEFT, "TCameraMenu", "Camera positions:", 350, 200, 10, mCameraMenuItems);
	mTrayMgr->removeWidgetFromTray(mCameraMenu);
	mCameraMenu->hide();

	mUpdateButton = mTrayMgr->createButton(OgreBites::TL_BOTTOMRIGHT,"TUpdateButton","Syncronize scene...",300);
	mTrayMgr->removeWidgetFromTray(mUpdateButton);
	mUpdateButton->hide();

	std::cout << ".";

	std::cout << "OK\n";
}

//-------------------------------------------------------------------------------------

SimulatorGui::~SimulatorGui(void)
{
}

//-------------------------------------------------------------------------------------

void SimulatorGui::injectCameras(Ogre::StringVector cameras)
{
	mCameraMenu->clearItems();
	mCameraMenu->addItem("");

	int count = cameras.size();
	for(int i=0;i<count;i++)
	{
		mCameraMenu->addItem(cameras.at(i));
	}
}

int SimulatorGui::getCameraSelection(void)
{
	return mCameraMenu->getSelectionIndex();
}

//-------------------------------------------------------------------------------------
	
void SimulatorGui::setGuimode(bool enabled)
{
		if (enabled)
		{
			mCameraMan->setStyle(CS_MANUAL);
			mTrayMgr->showCursor();
			bGuiMode = true;
		}
		else
		{
			mCameraMan->setStyle(CS_FREELOOK);
			mTrayMgr->hideCursor();
			bGuiMode = false;
		}
}

//-------------------------------------------------------------------------------------
	
void SimulatorGui::toggleGuimode(void)
{
		if (!bGuiMode)
		{
			mCameraMan->setStyle(CS_MANUAL);
			mTrayMgr->showCursor();
			bGuiMode = true;
		}
		else
		{
			mCameraMan->setStyle(CS_FREELOOK);
			mTrayMgr->hideCursor();
			bGuiMode = false;
		}
}
//--------------------------------------------------------------------------------------
void SimulatorGui::showLoadingLabel(Ogre::DisplayString text)
{
	mTrayMgr->moveWidgetToTray(mLoadingLabel,OgreBites::TL_CENTER);
	mLoadingLabel->show();

	mTrayMgr->removeWidgetFromTray(mCameraMenu);
	mCameraMenu->hide();

	mTrayMgr->removeWidgetFromTray(mUpdateButton);
	mUpdateButton->hide();

	mTrayMgr->hideFrameStats();
    mTrayMgr->showBackdrop("SdkTrays/Shade");

	mLoadingLabel->setCaption(text);
}

//--------------------------------------------------------------------------------------

void SimulatorGui::hideLoadingLabel(void)
{
	mTrayMgr->removeWidgetFromTray(mLoadingLabel);
	mLoadingLabel->hide();

	mTrayMgr->moveWidgetToTray(mCameraMenu,OgreBites::TL_TOPLEFT);
	mCameraMenu->show();

	mTrayMgr->moveWidgetToTray(mUpdateButton,OgreBites::TL_BOTTOMRIGHT);
	mUpdateButton->show();

	mTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
	mTrayMgr->hideBackdrop();
}
//--------------------------------------------------------------------------------------

void SimulatorGui::resetMenus(void)
{

}

//--------------------------------------------------------------------------------------